package org.zcode.generator.core.config;

import lombok.Data;
import org.mybatis.generator.api.IntrospectedTable;
import org.mybatis.generator.api.dom.java.FullyQualifiedJavaType;

/**
 * @Description:
 * @author zhoulk
 * @date: 2019/10/28
 */
@Data
public class BeanTypeConfig {
    public FullyQualifiedJavaType daoType;
    public FullyQualifiedJavaType interfaceType;//dataSource service接口
    public FullyQualifiedJavaType pojoType;//dataSource Base实体
    public FullyQualifiedJavaType pojoConditionType;//dataSource Conditon实体
    public FullyQualifiedJavaType addIPoType; //新增接口入参Bean
    public FullyQualifiedJavaType qryOPoType; //根据Id单个查询出参Bean
    public FullyQualifiedJavaType qrysOPoType; //列表查询出参Bean
    public FullyQualifiedJavaType qrysIPoType; //列表查询接口入参Bean
    public FullyQualifiedJavaType updIPoType; //更新接口入参Bean

    public static BeanTypeConfig init(IntrospectedTable introspectedTable, XmlConfig xmlConfig) {
        BeanTypeConfig beanTypeConfig = new BeanTypeConfig();
        String table = introspectedTable.getBaseRecordType();
        String tableName = table.replaceAll(xmlConfig.baseBeanPack + ".", "");

        beanTypeConfig.daoType = new FullyQualifiedJavaType(introspectedTable.getMyBatis3JavaMapperType());
        beanTypeConfig.interfaceType = new FullyQualifiedJavaType(xmlConfig.servicePack + ".I" + tableName.substring(xmlConfig.substring) + "Service");
        beanTypeConfig.pojoType = new FullyQualifiedJavaType(xmlConfig.baseBeanPack + "." + tableName);
        beanTypeConfig.pojoConditionType = new FullyQualifiedJavaType(xmlConfig.conditionBeanPack + "." + tableName + "Condition");

        String atomIPoPack_ = xmlConfig.atomIPoPack + "." + tableName.toLowerCase().substring(xmlConfig.substring);
        String atomOPoPack_ = xmlConfig.atomOPoPack + "." + tableName.toLowerCase().substring(xmlConfig.substring);
         beanTypeConfig.addIPoType = new FullyQualifiedJavaType(atomIPoPack_ + ".Add" + tableName.substring(xmlConfig.substring) + "IPo");
         beanTypeConfig.qryOPoType = new FullyQualifiedJavaType(atomOPoPack_ + ".Qry" + tableName.substring(xmlConfig.substring) + "OPo");
         beanTypeConfig.qrysOPoType = new FullyQualifiedJavaType(atomOPoPack_ + ".Qry" + tableName.substring(xmlConfig.substring) + "sOPo");
        beanTypeConfig.updIPoType = new FullyQualifiedJavaType(atomIPoPack_ + ".Upd" + tableName.substring(xmlConfig.substring) + "IPo");
        beanTypeConfig.qrysIPoType = new FullyQualifiedJavaType(atomIPoPack_ + ".Qry" + tableName.substring(xmlConfig.substring) + "sIPo");
        return beanTypeConfig;
    }

}
